#! /bin/sh -vx
# $Id$
# Copyright 2018-2021 Japanese TeX Development Community <issue@texjp.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_chkdvifont=$BinDir/chkdvifont$ExeExt

testdir=$srcdir/tests

DIFF="diff"
CMP="cmp"
# pre-generated test results in the repository are stored in LF
# but the output might be written in CRLF on some platform.
# if 'diff --strip-trailing-cr' is available, exploit it.
# (useful for tests on win32 binaries run on MSYS shell)
$DIFF --strip-trailing-cr $0 $0 \
  && DIFF="diff --strip-trailing-cr" || echo


## DVI mode

cp $testdir/oldindep.dvi . && \
  $_chkdvifont -c ./oldindep.dvi > xoldindep.cfn && \
  $DIFF $testdir/oldindep.cfn xoldindep.cfn && echo || exit 1


## TFM/JFM mode

$_chkdvifont -c $testdir/jis.tfm > xjis.cfn && \
  $DIFF $testdir/jis.cfn xjis.cfn && echo || exit 2

# eufm10.tfm is "AMSTeX 2.0 or newer", exit code should be 4
$_chkdvifont -c $testdir/eufm10.tfm > xeufm10.cfn
  if [ $? -ne 4 ]; then exit 3; fi
  sed 's!2.0/2.1!2.0 or newer!' xeufm10.cfn > xeufm10.ed.cfn
  $DIFF $testdir/eufm10.cfn xeufm10.ed.cfn && echo || exit 3


## FONT mode

$_chkdvifont -c $testdir/cmr10.pk > xcmr10.cfn && \
  $DIFF $testdir/cmr10.cfn xcmr10.cfn && echo || exit 4

echo M | $_chkdvifont && echo || exit 0

# the following tests will not pass for old version written by SHIMA.
# that version can be distinguished from the new version by
# exit code 250 for usage with stdin M. (the above line did it!)

# check VF format
$_chkdvifont -c $testdir/upjisr-h.vf > xupjisr-h.cfn && \
  $DIFF $testdir/upjisr-h.cfn xupjisr-h.cfn && echo || exit 5

# detect new JFM format
$_chkdvifont -c $testdir/uparse.tfm > xuparse.cfn && \
  $DIFF $testdir/uparse.cfn xuparse.cfn && echo || exit 6
$_chkdvifont -c $testdir/skipjfmp.tfm > xskipjfmp.cfn && \
  $DIFF $testdir/skipjfmp.cfn xskipjfmp.cfn && echo || exit 7
$_chkdvifont -c $testdir/upphirakakuw3-h.tfm > xupp3-h.cfn && \
  $DIFF $testdir/upphirakakuw3-h.cfn xupp3-h.cfn && echo || exit 8
$_chkdvifont -c $testdir/upphirakakuw6-h.tfm > xupp6-h.cfn && \
  $DIFF $testdir/upphirakakuw6-h.cfn xupp6-h.cfn && echo || exit 9


exit 0

